.macro Get_random 
	cbm.or   t6, t6, x0, 3
    cbm.srli t6, t6, 16, 3
.endm

.macro cbm_isw rX0, rX1, rY0, rY1, rRM, rZ0, rZ1, tmp
    cbm.and  \rZ0, \rX0, \rY0, 3
    xor  \rZ0, \rZ0, \rRM
    cbm.and  \rZ1, \rX0, \rY1, 3
    xor  \rZ1, \rZ1, \rRM
    cbm.and  \tmp, \rX1, \rY0, 3
    xor  \rZ1, \rZ1, \tmp
    cbm.and  \tmp, \rX1, \rY1, 3
    xor  \rZ1, \rZ1, \tmp
.endm

.global aes_sbox
.type aes_sbox, %function

aes_sbox:
    .include "ise.S"
    addi 	sp, sp, -(4*55)
    sw      t0, 0(sp)
	sw   	t1, 1*4(sp)
	sw   	t2, 2*4(sp)
	sw      s0, 3*4(sp)
	sw      s1, 4*4(sp)
	sw      a2, 5*4(sp)
	sw      a3, 6*4(sp)
	sw   	a4, 7*4(sp)
	sw   	a5, 8*4(sp)
	sw      a6, 9*4(sp)
	sw      a7, 10*4(sp)
	sw      s2, 11*4(sp)
	sw      s3, 12*4(sp)
	sw      s4, 13*4(sp)
	sw      s5, 14*4(sp)
	sw      s6, 15*4(sp)
	sw      s7, 16*4(sp)
	sw      s8, 17*4(sp)
	sw      s9, 18*4(sp)
	sw      s10,19*4(sp)
	sw      s11,20*4(sp)
	sw      t3, 21*4(sp)
	sw      t4, 22*4(sp)
	sw      t5, 23*4(sp)
	sw      t6, 24*4(sp)


    lw      s7, 3*4(a0)          //g3
    lw      s9, 5*4(a0)          //g5
    lw      a2, 11*4(a0)         //h3
    lw      a4, 13*4(a0)         //h5
    xor     a7, s7, s9        //y14_0 = g3 ^ g5   into a7
    xor     t0, a2, a4        //y14_1 = h3 ^ h5   into t0nop
    lw      s4, 0*4(a0)          //g0
    lw      s10, 6*4(a0)         //g6
    lw      t2, 8*4(a0)          //h0
    lw      a5, 14*4(a0)         //h6
    xor     s3, s4, s10       //y13_0 = g0 ^ g6   into s3
    xor     t1, t2, a5        //y13_1 = h0 ^ h6   into t1
    xor     s2, s3, a7        //y12_0 = y13_0 ^ y14_0   into s2
    xor     s5, t1, t0        //y12_1 = y13_1 ^ y14_1   into s5
    lw      s8, 4*4(a0)          //g4
    lw      a3, 12*4(a0)         //h4
    xor     a6, s8, s2        //t1_0 = g4 ^ y12_0   into a6
    xor     a3, a3, s5        //t1_1 = h4 ^ y12_1   into a3
    xor     t5, a6, s9        //y15_0 = t1_0 ^ g5   into t5
    xor     s10, a3, a4       //y15_1 = t1_1 ^ h5   into s10
    Get_random                   //random
    xor     s0, s2, t6        //y12_0r   into s0
    xor     s1, s5, t6        //y12_1r   into s1
    Get_random                   //random
    cbm_isw s0, s1, t5, s10, t6, t3, t4, s6     //isw t2_0, t2_1  into t3, t4
    sw      t3, 25*4(sp)         //store t2_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t4, 26*4(sp)         //store t2_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s11, 7*4(a0)         //g7
    lw      t4, 15*4(a0)         //h7
    xor     s8, t5, s11       //y6_0 = y15_0 ^ g7   into s8
    sw      s8, 27*4(sp)         //store y6_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    xor     s8, s10, t4       //y6_1 = y15_1 ^ h7   into s8
    sw      s8, 28*4(sp)         //store y6_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s2, 29*4(sp)         //store y12_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s5, 30*4(sp)         //store y12_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s5, 1*4(a0)          //g1
    lw      s0, 9*4(a0)          //h1
    xor     a6, a6, s5        //y20_0 = t1_0 ^ g1   into a6
    xor     a3, a3, s0        //y20_1 = t1_1 ^ h1   into a3
    xor     s2, s4, s7        //y9_0  = g0 ^ g3   into s2
    xor     s1, t2, a2        //y9_1  = h0 ^ h3   into s1
    sw      a6, 31*4(sp)         //store y20_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      a3, 32*4(sp)         //store y20_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    xor     a6, a6, s2        //y11_0 = y20_0 ^ y9_0   into a6
    xor     a3, a3, s1        //y11_1 = y20_1 ^ y9_1   into a3
    sw      s2, 33*4(sp)         //store y9_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s1, 34*4(sp)         //store y9_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Get_random                   //random
    xor     s8, s2, t6        //y9_0r   into s8
    xor     t3, s1, t6        //y9_1r   into t3
    Get_random                   //random
    cbm_isw s8, t3, a6, a3, t6, s2, s1, s6     //isw t12_0, t12_1  into s2, s1
    sw      s2, 35*4(sp)         //store t12_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s1, 36*4(sp)         //store t12_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    xor     s8, s11, a6       //y7_0 = g7 ^ y11_0   into s8
    xor     t3, t4, a3        //y7_1 = h7 ^ y11_1   into t3
    xor     s9, s4, s9        //y8_0 = g0 ^ g5   into s9
    xor     a4, t2, a4        //y8_1 = h0 ^ h5   into a4
    lw      s6, 2*4(a0)          //g2
    lw      s1, 10*4(a0)         //h2
    xor     s6, s5, s6        //t0_0 = g1 ^ g2   into s6
    xor     s1, s0, s1        //t0_1 = h1 ^ h2   into s1
    xor     s5, t5, s6        //y10_0 = y15_0 ^ t0_0   into s5
    xor     s0, s10, s1       //y10_1 = y15_1 ^ t0_1   into s0
    sw      t5, 37*4(sp)         //store y15_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s10, 38*4(sp)        //store y15_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    xor     t5, s5, a6        //y17_0 = y10_0 ^ y11_0   into t5
    xor     s10, s0, a3       //y17_1 = y10_1 ^ y11_1   into s10
    sw      a7, 39*4(sp)         //store y14_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t0, 40*4(sp)         //store y14_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Get_random                   //random
    xor     s4, a7, t6        //y14_0r   into s4
    xor     t2, t0, t6        //y14_1r   into t2
    Get_random                   //random
    cbm_isw s4, t2, t5, s10, t6, a7, t0, s2   //isw t13_0, t13_1  into a7, t0
    lw      s4, 35*4(sp)         //load t12_0
    lw      t2, 36*4(sp)         //load t12_1
    xor     a7, a7, s4        //t14_0 = t13_0 ^ t12_0   into a7
    xor     t0, t0, t2        //t14_1 = t13_1 ^ t12_1   into t0
    sw      t5, 41*4(sp)         //store y17_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s10, 42*4(sp)        //store y17_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    xor     t5, s5, s9        //y19_0 = y10_0 ^ y8_0   into t5
    xor     s10, s0, a4       //y19_1 = y10_1 ^ y8_1   into s10
    sw      s5, 43*4(sp)         //store y10_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s0, 44*4(sp)         //store y10_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Get_random                   //random
    xor     s7, s5, t6        //y10_0r   into s7
    xor     a2, s0, t6        //y10_1r   into a2
    Get_random                   //random
    cbm_isw s9, a4, s7, a2, t6, s5, s0, s2   //isw t15_0, t15_1  into s5, s0
    xor     s4, s5, s4        //t16_0 = t15_0 ^ t12_0   into s4
    xor     t2, s0, t2        //t16_1 = t15_1 ^ t12_1   into t2
    xor     s5, s6, a6        //y16_0 = t0_0 ^ y11_0   into s5
    xor     s0, s1, a3        //y16_1 = t0_1 ^ y11_1   into s0
    sw      a6, 35*4(sp)         //store y11_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      a3, 36*4(sp)         //store y11_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    xor     a6, s3, s5        //y21_0 = y13_0 ^ y16_0   into a6
    xor     a3, t1, s0        //y21_1 = y13_1 ^ y16_1   into a3
    sw      s3, 45*4(sp)         //store y13_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t1, 46*4(sp)         //store y13_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Get_random                   //random
    xor     s7, s3, t6        //y13_0r   into s7
    xor     a2, t1, t6        //y13_1r   into a2
    Get_random                   //random
    cbm_isw s7, a2, s5, s0, t6, s3, t1, s2   //isw t7_0, t7_1  into s3, t1
    sw      s5, 47*4(sp)         //store y16_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s0, 48*4(sp)         //store y16_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s7, 0*4(a0)          //g0
    lw      a2, 8*4(a0)          //h0
    xor     s5, s7, s5        //y18_0 = g0 ^ y16_0   into s5
    xor     s0, a2, s0        //y18_1 = h0 ^ y16_1   into s0
    xor     s6, s6, s11       //y1_0 = t0_0 ^ g7   into s6
    xor     s1, s1, t4        //y1_1 = t0_1 ^ h7   into s1
    lw      s7, 3*4(a0)          //g3
    lw      a2, 11*4(a0)         //h3
    xor     s7, s6, s7        //y4_0 = y1_0 ^ g3   into s7
    xor     a2, s1, a2        //y4_1 = y1_1 ^ h3   into a2
    sw      s3, 49*4(sp)         //store t7_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t1, 50*4(sp)         //store t7_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Get_random                   //random
    xor     s3, s11, t6       //g7r   into s3
    xor     t1, t4, t6        //h7r   into t1
    Get_random                   //random
    cbm_isw s7, a2, s3, t1, t6, s11, t4, s2   //isw t5_0, t5_1  into s11, t4
    lw      s3, 25*4(sp)         //load t2_0
    lw      t1, 26*4(sp)         //load t2_1
    xor     s11, s11, s3      //t6_0 = t5_0 ^ t2_0   into s11
    xor     t4, t4, t1        //t6_1 = t5_1 ^ t2_1   into t4
    xor     s11, s11, s4      //t18_0 = t6_0 ^ t16_0   into s11
    xor     t4, t4, t2        //t18_1 = t6_1 ^ t16_1   into t4
    xor     t5, s11, t5       //t22_0 = t18_0 ^ y19_0   into t5
    xor     s10, t4, s10      //t22_1 = t18_1 ^ y19_1   into s10
    sw      s4, 51*4(sp)         //store t16_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t2, 52*4(sp)         //store t16_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s4, 0*4(a0)          //g0
    lw      t2, 8*4(a0)          //h0
    xor     s4, s6, s4        //y2_0 = y1_0 ^ g0; into s4
    xor     t2, s1, t2        //y2_1 = y1_1 ^ h0; into t2
    sw      s7, 53*4(sp)         //store y4_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      a2, 54*4(sp)         //store y4_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Get_random                   //random
    xor     s7, s4, t6        //y2_0r   into s7
    xor     a2, t2, t6        //y2_1r   into a2
    Get_random                   //random
    cbm_isw s7, a2, s8, t3, t6, s11, t4, s2   //isw t10_0, t10_1  into s11, t4
    lw      s7, 49*4(sp)         //load t7_0
    lw      a2, 50*4(sp)         //load t7_1
    xor     s11, s11, s7      //t11_0 = t10_0 ^ t7_0   into s11
    xor     t4, t4, a2        //t11_1 = t10_1 ^ t7_1   into t4
    lw      s3, 51*4(sp)         //load t16_0
    lw      t1, 52*4(sp)         //load t16_1
    xor     s3, s11, s3       //t20_0 = t11_0 ^ t16_0   into s3
    xor     t1, t4, t1        //t20_1 = t11_1 ^ t16_1   into t1
    xor     s3, s3, s5        //t24_0 = t20_0 ^ y18_0   into s3
    xor     t1, t1, s0        //t24_1 = t20_1 ^ y18_1   into t1
    sw      t5, 51*4(sp)         //store t22_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s10, 52*4(sp)        //store t22_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s10, 6*4(a0)         //g6
    xor     s10, s6, s10      //y5_0 = y1_0 ^ g6; into s10
    xor     a5, s1, a5        //y5_1 = y1_1 ^ h6; into a5
    Get_random                   //random
    xor     s5, s10, t6       //y5_0r   into s5
    xor     s0, a5, t6        //y5_1r   into s0
    Get_random                   //random
    cbm_isw s5, s0, s6, s1, t6, s11, t4, s2   //isw t8_0, t8_1  into s11, t4
    xor     s7, s11, s7       //t9_0 = t8_0 ^ t7_0   into s7
    xor     a2, t4, a2        //t9_1 = t8_1 ^ t7_1   into a2
    xor     s7, s7, a7        //t19_0 = t9_0 ^ t14_0   into s7
    xor     a2, a2, t0        //t19_1 = t9_1 ^ t14_1   into a2
    xor     s7, s7, a6        //t23_0 = t19_0 ^ y21_0   into s7
    xor     a2, a2, a3        //t23_1 = t19_1 ^ y21_1   into a2
    xor     a6, s10, s9       //y3_0 = y5_0 ^ y8_0   into a6
    xor     a3, a5, a4        //y3_1 = y5_1 ^ y8_1   into a3
    lw      s11, 27*4(sp)        //load y6_0
    lw      t4, 28*4(sp)         //load y6_1
    Get_random                   //random
    xor     s11, s11, t6      //y6_0r   into s11
    xor     t4, t4, t6        //y6_1r   into t4
    Get_random                   //random
    cbm_isw a6, a3, s11, t4, t6, s5, s0, s2   //isw t3_0, t3_1  into s5, s0
    lw      s11, 25*4(sp)        //load t2_0
    lw      t4, 26*4(sp)         //load t2_1
    xor     s11, s5, s11      //t4_0 = t3_0 ^ t2_0   into s11
    xor     t4, s0, t4        //t4_1 = t3_1 ^ t2_1   into t4
    lw      s5, 31*4(sp)         //load y20_0
    lw      s0, 32*4(sp)         //load y20_1
    xor     s11, s11, s5      //t17_0 = t4_0 ^ y20_0   into s11
    xor     t4, t4, s0        //t17_1 = t4_1 ^ y20_1   into t4
    xor     a7, s11, a7       //t21_0 = t17_0 ^ t14_0   into a7
    xor     t0, t4, t0        //t21_1 = t17_1 ^ t14_1   into t0
    Get_random                   //random
    xor     s5, a7, t6        //t21_0r   into s5
    xor     s0, t0, t6        //t21_1r   into s0
    Get_random                   //random
    cbm_isw s5, s0, s7, a2, t6, s11, t4, s2   //isw t26_0, t26_1  into s11, t4
    xor     s5, s3, s11       //t27_0 = t24_0 ^ t26_0   into s5
    xor     s0, t1, t4        //t27_1 = t24_1 ^ t26_1   into s0
    sw      s10, 25*4(sp)        //store y5_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      a5, 26*4(sp)         //store y5_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      a5, 52*4(sp)         //load t22_1
    xor     s11, t5, s11      //t31_0 = t22_0 ^ t26_0   into s11
    xor     t4, a5, t4        //t31_1 = t22_1 ^ t26_1   into t4
    xor     a7, a7, t5        //t25_0 = t21_0 ^ t22_0   into a7
    xor     t0, t0, a5        //t25_1 = t21_1 ^ t22_1   into t0
    sw      a7, 31*4(sp)         //store t25_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t0, 32*4(sp)         //store t25_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Get_random                   //random
    xor     a7, a7, t6        //t25_0r   into a7
    xor     t0, t0, t6        //t25_1r   into t0
    Get_random                   //random
    sw      s7, 49*4(sp)         //store t23_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      a2, 50*4(sp)         //store t23_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    cbm_isw a7, t0, s5, s0, t6, s7, a2, s2   //isw t28_0, t28_1  into s7, a2
    xor     t5, s7, t5        //t29_0 = t28_0 ^ t22_0   into t5
    xor     a5, a2, a5        //t29_1 = t28_1 ^ t22_1   into a5
    Get_random                   //random
    xor     a7, s4, t6        //y2_0r   into a7
    xor     t0, t2, t6        //y2_1r   into t0
    Get_random                   //random
    cbm_isw t5, a5, a7, t0, t6, s4, t2, s2   //isw z14_0, z14_1  into s4, t2
    Get_random                   //random
    xor     a7, s8, t6        //y7_0r   into a7
    xor     t0, t3, t6        //y7_1r   into t0
    Get_random                   //random
    cbm_isw t5, a5, a7, t0, t6, s8, t3, s2   //isw z5_0, z5_1  into s8, t3
    lw      s10, 49*4(sp)        //load t23_0
    xor     s7, s10, s3       //t30_0 = t23_0 ^ t24_0   into s7
    li      s10, 0
    lw      s10, 50*4(sp)        //load t23_1
    xor     a2, s10, t1       //t30_1 = t23_1 ^ t24_1   into a2
    Get_random                   //random
    xor     a7, s11, t6       //t31_0r   into a7
    xor     t0, t4, t6        //t31_1r   into t0
    Get_random                   //random
    cbm_isw a7, t0, s7, a2, t6, s11, t4, s2   //isw t32_0, t32_1  into s11, t4
    xor     s11, s11, s3      //t33_0 = t32_0 ^ t24_0   into s11
    xor     t4, t4, t1        //t33_1 = t32_1 ^ t24_1   into t4
    xor     s7, s5, s11       //t35_0 = t27_0 ^ t33_0   into s7
    xor     a2, s0, t4        //t35_1 = t27_1 ^ t33_1   into a2
    Get_random                   //random
    xor     a7, s3, t6        //t24_0r   into a7
    xor     t0, t1, t6        //t24_1r   into t0
    Get_random                   //random
    cbm_isw a7, t0, s7, a2, t6, s3, t1, s2   //isw t36_0, t36_1  into s3, t1
    xor     s5, s5, s3        //t38_0 = t27_0 ^ t36_0   into s5
    xor     s0, s0, t1        //t38_1 = t27_1 ^ t36_1   into s0
    Get_random                   //random
    xor     a7, s5, t6        //t38_0r   into a7
    xor     t0, s0, t6        //t38_1r   into t0
    Get_random                   //random
    cbm_isw t5, a5, a7, t0, t6, s5, s0, s2   //isw t39_0, t39_1  into s5, s0
    sw      s4, 51*4(sp)         //store z14_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t2, 52*4(sp)         //store z14_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      a7, 31*4(sp)         //load t25_0
    lw      t0, 32*4(sp)         //load t25_1
    xor     a7, a7, s5        //t40_0 = t25_0 ^ t39_0   into a7
    xor     t0, t0, s0        //t40_1 = t25_1 ^ t39_1   into t0
    xor     s5, t5, a7        //t43_0 = t29_0 ^ t40_0   into s5
    xor     s0, a5, t0        //t43_1 = t29_1 ^ t40_1   into s0
    lw      s7, 47*4(sp)         //load y16_0
    lw      a2, 48*4(sp)         //load y16_1
    Get_random                   //random
    xor     s4, s7, t6        //y16_0r   into s4
    xor     t2, a2, t6        //y16_1r   into t2
    Get_random                   //random
    cbm_isw s5, s0, s4, t2, t6, s7, a2, s2   //isw z3_0, z3_1  into s7, a2
    xor     s8, s7, s8        //tc12_0 = z3_0 ^ z5_0   into s8
    xor     t3, a2, t3        //tc12_1 = z3_1 ^ z5_1   into t3
    sw      s8, 31*4(sp)         //store tc12_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t3, 32*4(sp)         //store tc12_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s8, 45*4(sp)         //load y13_0
    lw      t3, 46*4(sp)         //load y13_1
    Get_random                   //random
    xor     s4, s8, t6        //y13_0r   into s4
    xor     t2, t3, t6        //y13_1r   into t2
    Get_random                   //random
    cbm_isw s5, s0, s4, t2, t6, s8, t3, s2   //isw z12_0, z12_1  into s8, t3
    lw      s5, 25*4(sp)         //load y5_0
    lw      s0, 26*4(sp)         //load y5_1
    Get_random                   //random
    xor     s4, s5, t6        //y5_0r   into s4
    xor     t2, s0, t6        //y5_1r   into t2
    Get_random                   //random
    cbm_isw a7, t0, s4, t2, t6, s5, s0, s2   //isw z13_0, z13_1  into s5, s0
    Get_random                   //random
    xor     s4, s6, t6        //y1_0r   into s4
    xor     t2, s1, t6        //y1_1r   into t2
    Get_random                   //random
    cbm_isw a7, t0, s4, t2, t6, s6, s1, s2   //isw z4_0, z4_1  into s6, s1
    xor     s6, s7, s6        //tc6_0 = z3_0 ^ z4_0   into s6
    xor     s1, a2, s1        //tc6_1 = z3_1 ^ z4_1   into s1
    lw      s4, 49*4(sp)         //load t23_0
    lw      t2, 50*4(sp)         //load t23_1
    xor     s4, s4, s11       //t34_0 = t23_0 ^ t33_0   into s4
    xor     t2, t2, t4        //t34_1 = t23_1 ^ t33_1   into t2
    xor     s4, s3, s4        //t37_0 = t36_0 ^ t34_0   into s4
    xor     t2, t1, t2        //t37_1 = t36_1 ^ t34_1   into t2
    xor     a7, a7, s4        //t41_0 = t40_0 ^ t37_0   into a7
    xor     t0, t0, t2        //t41_1 = t40_1 ^ t37_1   into t0
    sw      s5, 25*4(sp)         //store z13_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      s0, 26*4(sp)         //store z13_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s5, 43*4(sp)         //load y10_0
    lw      s0, 44*4(sp)         //load y10_1
    Get_random                   //random
    xor     s7, s5, t6        //y10_0r   into s7
    xor     a2, s0, t6        //y10_1r   into a2
    Get_random                   //random
    cbm_isw a7, t0, s7, a2, t6, s3, t1, s2   //isw z8_0, z8_1  into s3, t1
    Get_random                   //random
    xor     s7, s9, t6        //y8_0r   into s7
    xor     a2, a4, t6        //y8_1r   into a2
    Get_random                   //random
    cbm_isw a7, t0, s7, a2, t6, s9, a4, s2   //isw z17_0, z17_1  into s9, a4
    sw      s9, 43*4(sp)         //store z17_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      a4, 44*4(sp)         //store z17_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    xor     s5, s11, s4       //t44_0 = t33_0 ^ t37_0   into s5
    xor     s0, t4, t2        //t44_1 = t33_1 ^ t37_1   into s0
    lw      s9, 37*4(sp)         //load y15_0
    lw      a4, 38*4(sp)         //load y15_1
    Get_random                   //random
    xor     s7, s9, t6        //y15_0r   into s7
    xor     a2, a4, t6        //y15_1r   into a2
    Get_random                   //random
    cbm_isw s5, s0, s7, a2, t6, s9, a4, s2   //isw z0_0, z0_1  into s9, a4
    sw      s3, 37*4(sp)         //store z8_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t1, 38*4(sp)         //store z8_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s7, 29*4(sp)         //load y12_0
    lw      a2, 30*4(sp)         //load y12_1
    Get_random                   //random
    xor     s3, s7, t6        //y12_0r   into s3
    xor     t1, a2, t6        //y12_1r   into t1
    Get_random                   //random
    cbm_isw s5, s0, s3, t1, t6, s7, a2, s2   //isw z9_0, z9_1  into s7, a2
    Get_random                   //random
    xor     s3, a6, t6        //y3_0r   into s3
    xor     t1, a3, t6        //y3_1r   into t1
    Get_random                   //random
    cbm_isw s4, t2, s3, t1, t6, a6, a3, s2   //isw z10_0, z10_1  into a6, a3
    lw      s3, 27*4(sp)         //load y6_0
    lw      t1, 28*4(sp)         //load y6_1
    Get_random                   //random
    xor     s5, s3, t6        //y6_0r   into s5
    xor     s0, t1, t6        //y6_1r   into s0
    Get_random                   //random
    cbm_isw s4, t2, s5, s0, t6, s3, t1, s2   //isw z1_0, z1_1  into s3, t1
    xor     s3, s3, s9        //tc5_0 = z1_0 ^ z0_0   into s3
    xor     t1, t1, a4        //tc5_1 = z1_1 ^ z0_1   into t1
    xor     s3, s6, s3        //tc11_0 = tc6_0 ^ tc5_0   into s3
    xor     t1, s1, t1        //tc11_1 = tc6_1 ^ tc5_1   into t1
    lw      s4, 53*4(sp)         //load y4_0
    lw      t2, 54*4(sp)         //load y4_1
    Get_random                   //random
    xor     s5, s4, t6        //y4_0r   into s5
    xor     s0, t2, t6        //y4_1r   into s0
    Get_random                   //random
    cbm_isw s11, t4, s5, s0, t6, s4, t2, s2   //isw z11_0, z11_1  into s4, t2
    xor     t5, t5, s11       //t42_0 = t29_0 ^ t33_0   into t5
    xor     a5, a5, t4        //t42_1 = t29_1 ^ t33_1   into a5
    xor     a7, t5, a7        //t45_0 = t42_0 ^ t41_0   into a7
    xor     t0, a5, t0        //t45_1 = t42_1 ^ t41_1   into t0
    sw      s3, 27*4(sp)         //store tc11_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t1, 28*4(sp)         //store tc11_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s5, 41*4(sp)         //load y17_0
    lw      s0, 42*4(sp)         //load y17_1
    Get_random                   //random
    xor     s3, s5, t6        //y17_0r   into s3
    xor     t1, s0, t6        //y17_1r   into t1
    Get_random                   //random
    cbm_isw a7, t0, s3, t1, t6, s5, s0, s2   //isw z7_0, z7_1  into s5, s0
    xor     s6, s5, s6        //tc8_0 = z7_0 ^ tc6_0   into s6
    xor     s1, s0, s1        //tc8_1 = z7_1 ^ tc6_1   into s1
    lw      s5, 39*4(sp)         //load y14_0
    lw      s0, 40*4(sp)         //load y14_1
    Get_random                   //random
    xor     s3, a7, t6        //t45_0r   into s3
    xor     t1, t0, t6        //t45_1r   into t1
    Get_random                   //random
    cbm_isw s3, t1, s5, s0, t6, a7, t0, s2   //isw z16_0, z16_1  into a7, t0
    lw      s5, 35*4(sp)         //load y11_0
    lw      s0, 36*4(sp)         //load y11_1
    Get_random                   //random
    xor     s3, s5, t6        //y11_0r   into s3
    xor     t1, s0, t6        //y11_1r   into t1
    Get_random                   //random
    cbm_isw t5, a5, s3, t1, t6, s5, s0, s2   //isw z6_0, z6_1  into s5, s0
    xor     s5, s5, s6        //tc16_0 = z6_0 ^ tc8_0   into s5
    xor     s0, s0, s1        //tc16_1 = z6_1 ^ tc8_1   into s0
    sw      s4, 29*4(sp)         //store z11_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t2, 30*4(sp)         //store z11_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s4, 33*4(sp)         //load y9_0
    lw      t2, 34*4(sp)         //load y9_1
    Get_random                   //random
    xor     s3, s4, t6        //y9_0r   into s3
    xor     t1, t2, t6        //y9_1r   into t1
    Get_random                   //random
    cbm_isw t5, a5, s3, t1, t6, s4, t2, s2   //isw z15_0, z15_1  into s4, t2
    xor     t5, s4, s5        //tc20_0 = z15_0 ^ tc16_0   into t5
    xor     a5, t2, s0        //tc20_1 = z15_1 ^ tc16_1   into a5
    xor     s4, s4, a7        //tc1_0 = z15_0 ^ z16_0   into s4
    xor     t2, t2, t0        //tc1_1 = z15_1 ^ z16_1   into t2
    xor     a7, a6, s4        //tc2_0 = z10_0 ^ tc1_0   into a7
    xor     t0, a3, t2        //tc2_1 = z10_1 ^ tc1_1   into t0
    sw      s11, 33*4(sp)        //store t33_0  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    sw      t4, 34*4(sp)         //store t33_1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    lw      s11, 29*4(sp)        //load z11_0
    lw      t4, 30*4(sp)         //load z11_1
    xor     a6, a7, s11       //tc21_0 = tc2_0 ^ z11_0   into a6
    xor     a3, t0, t4        //tc21_1 = tc2_1 ^ z11_1   into a3
    xor     s7, s7, a7        //tc3_0 = z9_0 ^ tc2_0   into s7
    xor     a2, a2, t0        //tc3_1 = z9_1 ^ tc2_1   into a2
    xor     a7, s7, s5        //S0_0 = tc3_0 ^ tc16_0   into a7                   //output_s[0]
    xor     t0, a2, s0        //S0_1 = tc3_1 ^ tc16_1   into t0                   //output_s[8]
    sw      a7, 0*4(a1)          //store S0_0
    sw      t0, 8*4(a1)          //store S0_1
    lw      s3, 27*4(sp)         //load tc11_0
    lw      t1, 28*4(sp)         //load tc11_1
    xor     s7, s7, s3        //S3_0 = tc3_0 ^ tc11_0   into s7                   //output_s[3]
    xor     a2, a2, t1        //S3_1 = tc3_1 ^ tc11_1   into a2                   //output_s[11]
    sw      s7, 3*4(a1)          //store S3_0
    sw      a2, 11*4(a1)         //store S3_1
    xor     s3, s7, s5        //S1_0 = S3_0 ^ tc16_0   into s3                    //output_s[1]  !!!!
    xor     t1, a2, s0        //S1_1 = S3_1 ^ tc16_1   into t1                    //output_s[9]  !!!!
    sw      s3, 1*4(a1)          //store S1_0
    sw      t1, 9*4(a1)          //store S1_1
    lw      s5, 25*4(sp)         //load z13_0
    lw      s0, 26*4(sp)         //load z13_1
    xor     s11, s5, s4       //tc13_0 = z13_0 ^ tc1_0   into s11
    xor     t4, s0, t2        //tc13_1 = z13_1 ^ tc1_1   into t4
    lw      s4, 7*4(a0)          //g7
    lw      t2, 15*4(a0)         //h7
    lw      s5, 33*4(sp)         //load t33_0
    lw      s0, 34*4(sp)         //load t33_1
    Get_random                   //random
    xor     s3, s5, t6        //t33_0r   into s3
    xor     t1, s0, t6        //t33_1r   into t1
    Get_random                   //random
    cbm_isw s3, t1, s4, t2, t6, s5, s0, s2   //isw z2_0, z2_1  into s5, s0
    xor     s9, s9, s5        //tc4_0 = z0_0 ^ z2_0   into s9
    xor     a4, a4, s0        //tc4_1 = z0_1 ^ z2_1   into a4
    xor     s5, s8, s9        //tc7_0 = z12_0 ^ tc4_0   into s5
    xor     s0, t3, a4        //tc7_1 = z12_1 ^ tc4_1   into s0
    lw      s3, 37*4(sp)         //load z8_0
    lw      t1, 38*4(sp)         //load z8_1
    xor     s3, s3, s5        //tc9_0 = z8_0 ^ tc7_0   into s3
    xor     t1, t1, s0        //tc9_1 = z8_1 ^ tc7_1   into t1
    xor     s3, s6, s3        //tc10_0 = tc8_0 ^ tc9_0   into s3
    xor     t1, s1, t1        //tc10_1 = tc8_1 ^ tc9_1   into t1
    lw      s4, 51*4(sp)         //load z14_0
    lw      t2, 52*4(sp)         //load z14_1
    xor     s5, s4, s3        //tc17_0 = z14_0 ^ tc10_0   into s5
    xor     s0, t2, t1        //tc17_1 = z14_1 ^ tc10_1   into s0
    xor     a6, a6, s5        //S5_0 = tc21_0 ^ tc17_0   into a6                   //output_s[5]
    xor     a3, a3, s0        //S5_1 = tc21_1 ^ tc17_1   into a3                   //output_s[13]
    sw      a6, 5*4(a1)          //store S5_0
    sw      a3, 13*4(a1)         //store S5_1
    xor     s6, s5, t5        //tc26_0 = tc17_0 ^ tc20_0   into s6
    xor     s1, s0, a5        //tc26_1 = tc17_1 ^ tc20_1   into s1
    lw      s4, 43*4(sp)         //load z17_0
    lw      t2, 44*4(sp)         //load z17_1
    lw      s5, 31*4(sp)         //load tc12_0
    lw      s0, 32*4(sp)         //load tc12_1
    xor     s6, s6, s4        //S2_0 = tc26_0 ^ z17_0   into s6                    //output_s[2]  !!!!
    xor     s1, s1, t2        //S2_1 = tc26_1 ^ z17_1   into s1                    //output_s[10]  !!!!
    sw      s6, 2*4(a1)          //store S2_0
    sw      s1, 10*4(a1)         //store S2_1
    xor     s5, s9, s5        //tc14_0 = tc4_0 ^ tc12_0   into s5
    xor     s0, a4, s0        //tc14_1 = tc4_1 ^ tc12_1   into s0
    xor     t5, s11, s5       //tc18_0 = tc13_0 ^ tc14_0   into t5
    xor     a5, t4, s0        //tc18_1 = tc13_1 ^ tc14_1   into a5
    xor     s3, s3, t5        //S6_0 = tc10_0 ^ tc18_0   into s3                    //output_s[6]  !!!!
    xor     t1, t1, a5        //S6_1 = tc10_1 ^ tc18_1   into t1                    //output_s[14]  !!!!
    sw      s3, 6*4(a1)          //store S6_0
    sw      t1, 14*4(a1)         //store S6_1
    xor     s11, s8, t5       //S7_0 = z12_0 ^ tc18_0   into s11                    //output_s[7]  !!!!
    xor     t4, t3, a5        //S7_1 = z12_1 ^ tc18_1   into t4                     //output_s[15]  !!!!
    sw      s11, 7*4(a1)         //store S7_0
    sw      t4, 15*4(a1)         //store S7_1
    xor     s8, s5, s7        //S4_0 = tc14_0 ^ S3_0   into s8                   //output_s[4]
    xor     t3, s0, a2        //S4_1 = tc14_1 ^ S3_1   into t3                   //output_s[12]
    sw      s8, 4*4(a1)          //store S4_0
    sw      t3, 12*4(a1)         //store S4_1

    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop

    lw      t0, 0(sp)
	lw   	t1, 1*4(sp)
	lw   	t2, 2*4(sp)
	lw      s0, 3*4(sp)
	lw      s1, 4*4(sp)
	lw      a2, 5*4(sp)
	lw      a3, 6*4(sp)
	lw   	a4, 7*4(sp)
	lw   	a5, 8*4(sp)
	lw      a6, 9*4(sp)
	lw      a7, 10*4(sp)
	lw      s2, 11*4(sp)
	lw      s3, 12*4(sp)
	lw      s4, 13*4(sp)
	lw      s5, 14*4(sp)
	lw      s6, 15*4(sp)
	lw      s7, 16*4(sp)
	lw      s8, 17*4(sp)
	lw      s9, 18*4(sp)
	lw      s10,19*4(sp)
	lw      s11,20*4(sp)
	lw      t3, 21*4(sp)
	lw      t4, 22*4(sp)
	lw      t5, 23*4(sp)
	lw      t6, 24*4(sp)
    addi 	sp, sp, 4*55
    ret